package org.dialMsg.Mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.dialMsg.Pojo.TDialResult;

import java.util.List;

/**
 * @author DPF
 */
@Mapper
public interface TDialResultMapper {
    int insert(TDialResult tDialResult);

    List<TDialResult> queryIdByPhone(String phone);

    @Select("SELECT id,business_id as businessId,account_id as accountId, outbound_number as outboundNumber, robot_id as robotId,data_source_batch_detail_id as dataSourceBatchDetailId,phone,bank_org as bankOrg,follow_user as followUser ,bank_manager as bankManager,dail_time as dailTime,call_time as callTime,duration_of_seat_conversing as durationOfSeatConversing,call_status as callStatus,call_type as callType,bridge_result as bridgeResult,data_source_batch_id as dataSourceBatchId,show_name as showName" +
            " FROM t_dial_result WHERE id > #{lastMaxId} AND phone = #{phone}")
    List<TDialResult> queryIdByPhoneAfter(@Param("lastMaxId") Long lastMaxId, @Param("phone") String phone);
    @Update("UPDATE t_dial_result SET human_status  = #{tDialResult.humanStatus} ,need_follow_up = 1 WHERE id > #{lastMaxId} AND phone = #{tDialResult.phone}")
    int updateHumanStatus(@Param("lastMaxId") Long lastMaxId, @Param("tDialResult") TDialResult tDialResult);
     @Select("SELECT min(id) FROM t_dial_result where phone = '111222333444' and need_follow_up = 0 ")
     int queryMaxId();
    @Select("SELECT id,business_id as businessId,account_id as accountId, outbound_number as outboundNumber, robot_id as robotId,data_source_batch_detail_id as dataSourceBatchDetailId,phone,bank_org as bankOrg,follow_user as followUser ,bank_manager as bankManager,dail_time as dailTime,call_time as callTime,duration_of_seat_conversing as durationOfSeatConversing,call_status as callStatus,call_type as callType,bridge_result as bridgeResult,data_source_batch_id as dataSourceBatchId,show_name as showName" +
            " FROM t_dial_result WHERE id > #{lastMaxId} AND phone = #{phone} LIMIT #{batchSize}")
    List<TDialResult> queryIdByPhoneAfter1(@Param("lastMaxId") Long lastMaxId, @Param("phone") String phone, @Param("batchSize") int batchSize);
    @Select("SELECT id FROM t_dial_result where phone != '111222333444' order by id desc limit 1")
    Integer queryCurrentMaxId();
}
